package com.ys.controller.api.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ys.util.admin.ConditionUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.ys.entity.sys.YsMenu;
import com.ys.entity.sys.YsRowClickGridCol;
import com.ys.enume.sys.YsRowClickGridColEnum;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.YsRowClickGridColService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

import java.util.Map;

@Controller
@RequestMapping("/api/inter/ysRowClickGridCol")
public class ApiInterYsRowClickGridColController {
	
//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);
	
	@Autowired
	private CommonApiService<YsRowClickGridCol> commonApiService;
	@Autowired
	private YsRowClickGridColService ysRowClickGridColService;

	//@RequiresPermissions("ysRowClickGridCol:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
								 @ModelAttribute YsRowClickGridCol cond,
								 String conditions, String rowConditions,String rowClickGridId
			){
		if(rowClickGridId!=null && !"".equals(rowClickGridId)){
			cond.setRowClickGridId(Long.parseLong(rowClickGridId));
		}


		cond.addLeftJoin("YS_RowClickGrid B on B.Id = A.RowClickGridId")
			.addField("B.name nameGrid");
		
		cond.setOrderby("A.SortNo asc,A.RowClickGridId asc");
		
		return commonApiService.searchLay(cond);
	}
	
	/**
	 * 新增
	 */
	@PostMapping("/add")
	@ResponseBody
	public R add(HttpServletRequest request,
			Long gridId,
			String name,
			String code,
			Integer sortNo,
			String frontType,
			Integer frontEdit,
			Integer frontWidth,
			Integer frontAlign,
			Integer frontShow,
			String dictKeyBase,
			String modalKey,
			String modalRelativeCode,
			String modalValueCode,
			Integer multyFileSourceType){
		return ysRowClickGridColService.add(gridId, name, code, sortNo, frontType, frontEdit, frontWidth, frontAlign, frontShow, dictKeyBase, modalKey, modalRelativeCode, modalValueCode, multyFileSourceType);
	}
	
	/**
	 * 新增单个
	 */
	@PostMapping("/addSingle")
	@ResponseBody
	public R addSingle(Long menuId){
		
		if (menuId == null) {
			return R.error("子列表所属菜单ID不能为空");
		}
		YsMenu ysMenu = new YsMenu().setId(menuId).queryFirst();
		Long rowClickGridId = ysMenu.getRowClickGridId();
		if (rowClickGridId == null) {
			return R.error("尚未配置子列表");
		}
		
		String code = "codexxx";
		String name = "待完善字段名";
		Integer frontWidth = 160;
		Integer frontAlign = YsRowClickGridColEnum.FrontAlign.CENTER.value;
		Integer sortNo = 999;
		String frontType = YsRowClickGridColEnum.FrontType.TEXT.value;
		Integer frontEdit = YsRowClickGridColEnum.FrontEdit.NO.value;
		Integer frontShow = YsRowClickGridColEnum.FrontShow.SHOW.value;
		String dictKeyBase = null;
		String modalKey = null;
		String modalRelativeCode = null;
		String modalValueCode = null;
		Integer multyFileSourceType = null;
			ysRowClickGridColService.add(rowClickGridId, name, code, sortNo, frontType, frontEdit, frontWidth, frontAlign, frontShow, dictKeyBase, modalKey, modalRelativeCode, modalValueCode, multyFileSourceType);
		return R.ok();
	}
	
	/*
	 * 删除
	 */
//	@RequiresPermissions("ysDict:delete")
	@PostMapping("/deleteTrue")
	@ResponseBody
	public R deleteTrue(HttpServletRequest request, HttpServletResponse response,
			Long id) {
		return ysRowClickGridColService.deleteTrue(id);
	}
	
	/**
	 * 配置选项
	 */
	@PostMapping("/settingOption")
    @ResponseBody
	public R settingOption(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id, String dictKeyBase){
		return ysRowClickGridColService.settingOption(id, dictKeyBase);
	}
	
	/**
	 * 配置弹出框
	 */
	@PostMapping("/settingSelectorModal")
    @ResponseBody
	public R settingSelectorModal(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id, Long idYsModalSelector){
		return ysRowClickGridColService.settingSelectorModal(id, idYsModalSelector);
	}
	
	/**
	 * 配置文件来源类型
	 */
	@PostMapping("/settingMultyFileSourceType")
    @ResponseBody
	public R settingMultyFileSourceType(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id, Integer multyFileSourceType){
		return ysRowClickGridColService.settingMultyFileSourceType(id, multyFileSourceType);
	}
	
	/**
	 * 新增字典（选择框）
	 */
	@PostMapping("/addDictForSelector")
    @ResponseBody
	public R addDictForSelector(Model model, HttpServletRequest request, HttpServletResponse response,
			Long colId, String dictName, String dictValue){
		return ysRowClickGridColService.addDictForSelector(colId, dictName, dictValue);
	}
	
	/**
	 * 编辑字典（选择框）
	 */
	@PostMapping("/editDictForSelector")
    @ResponseBody
	public R editDictForSelector(Model model, HttpServletRequest request, HttpServletResponse response,
			Long dictId, String dictName, String dictValue){
		return ysRowClickGridColService.editDictForSelector(dictId, dictName, dictValue);
	}
	
}
